#include <iostream>
#include "foohelper.h"
#include "dbus_adaptor.h"
#include <QCoreApplication>
#include <QDBusConnection>
#include <QDebug>


using namespace std;

int main(int argc, char **argv)
{
    FooHelper *dbus = new FooHelper();
    //创建适配器
    new DbusAdaptor(dbus);

    QCoreApplication app(argc, argv);

    //建立session bus的连接
    QDBusConnection connection = QDBusConnection::systemBus();
    //注册一个org.redflag.foohelper服务
    if (!connection.registerService("com.redflag.install.dbus")) {
        qDebug() << "另一个助手已经在运行";
        QCoreApplication::instance()->quit();
    }
    //注册一个org/redflag/foohelper对象
    if (!connection.registerObject("/com/redflag/install/dbus", dbus)) {
        qDebug() << "无法向dbus注册服务接口";
        QCoreApplication::instance()->quit();
    }
    qDebug()<<"服务端运行";
    //进入主事件循环并等待
    return app.exec();
}
